"""
Vehicle 模块 - PicknBuy24 车辆完整信息模型 (合并所有字段)
"""
from sqlalchemy import Column, String, Text, JSON, BigInteger, Integer, DECIMAL
from axiom_boot.database.base_model import BaseModel
from sqlalchemy.orm import Mapped, mapped_column
from axiom_boot.core.types import BigInt


class VehiclePicknbuy24(BaseModel):
    """PicknBuy24 车辆完整信息表 - 包含所有必要字段"""
    
    __tablename__ = 'vehicle_picknbuy24'

    # 显式重写 id 以符合【主键覆盖原则】
    id: Mapped[BigInt] = mapped_column(BigInteger, primary_key=True, comment="主键ID (雪花ID)")
    
    # 业务标识
    source = Column(String(20), default='picknbuy24', comment='数据来源')
    ref_no = Column(String(50), unique=True, nullable=False, comment='车辆参考号 (如: 0100932225)')
    detail_url = Column(Text, comment='车辆详情页URL')
    
    # 基本车辆信息 - 从详情页标题提取
    year = Column(String(10), comment='年份 (如: 2008)')
    make = Column(String(50), comment='品牌 (如: DAIHATSU)')
    model = Column(String(100), comment='型号 (如: MOVE L)')
    vehicle_type = Column(String(20), comment='车辆类型 (SEDAN, SUV, WAGON, COMPACT, SPORTY, TRUCK, VAN, SPECIAL, UNKNOWN)')
    vehicle_type_confidence = Column(String(10), default='UNKNOWN', comment='类型推断置信度 (HIGH, MEDIUM, LOW, UNKNOWN)')
    
    # 价格信息
    currency = Column(String(10), default='USD', comment='货币类型 (USD, JPY, EUR等)')
    price = Column(DECIMAL(12, 2), comment='当前价格数值 (如: 3040.00)')
    price_original = Column(String(50), comment='原始价格文本 (如: US$ 3,040)')
    price_before_discount = Column(DECIMAL(12, 2), comment='折扣前价格 (如: 3090.00)')
    discount_amount = Column(DECIMAL(12, 2), comment='折扣金额 (如: 50.00)')
    has_discount = Column(Integer, default=0, comment='是否有折扣 (0-无折扣, 1-有折扣)')
    
    # 技术规格 - 基于详情页表格
    mileage_km = Column(Integer, comment='里程公里数值 (如: 58000)')
    mileage_miles = Column(Integer, comment='里程英里数值 (如: 36000)')
    engine_cc = Column(Integer, comment='发动机排量数值 (如: 658)')
    fuel_type = Column(String(20), comment='燃料类型 (如: Petrol)')
    transmission = Column(String(30), comment='变速箱 (如: MT ( F 5))')
    drivetrain = Column(String(20), comment='驱动方式 (如: 2WD)')
    steering = Column(String(10), comment='方向盘位置 (如: Right)')
    
    # 车身信息
    seats = Column(String(10), comment='座位数 (如: 4)')
    doors = Column(String(10), comment='车门数 (如: 5)')
    color = Column(String(30), comment='颜色 (如: White)')
    
    # 车辆尺寸和重量 - Specs部分
    length_m = Column(String(15), comment='长度 (如: 3.39 m)')
    width_m = Column(String(15), comment='宽度 (如: 1.47 m)')
    height_m = Column(String(15), comment='高度 (如: 1.63 m)')
    weight_kg = Column(String(15), comment='重量 (如: 1,040 kg)')
    cubic_meter = Column(String(15), comment='体积立方米 (如: 8.2 m3)')
    
    # PicknBuy24特有字段 - Specs部分
    chassis = Column(String(50), comment='底盘型号 (如: DBA- L175S)')
    chassis_no_full = Column(String(50), comment='完整底盘号 (如: L175S-0180219)')
    reg_year_month = Column(String(20), comment='注册年月 (如: 2008/Sep)')
    location = Column(String(100), comment='车辆位置 (如: Yokohama)')
    engine_type = Column(String(50), comment='发动机类型')
    seatbelts_year = Column(String(10), comment='安全带年份')
    
    # 配置信息 - 严格按照页面Features分类
    exterior_options = Column(JSON, comment='外观选项 (HID Xenon Light, Power Mirrors, Sun Roof等)')
    interior_options = Column(JSON, comment='内饰选项 (Steering Wheel Remote Control, ECM, Leather Seat等)')
    safety_features = Column(JSON, comment='安全配置 (Driver Airbag, Passenger Airbag, Side Airbag等)')
    convenient_features = Column(JSON, comment='便利配置 (Power Steering, Auto Air Condition, Smart Key等)')
    multimedia_features = Column(JSON, comment='多媒体配置 (CD Player, CD Changer, Back Seat TV等)')
    equipment_features = Column(JSON, comment='装备配置 (Jack, Tool kit, Tire repair kit等)')
    
    # 特殊标注 - Remarkable Features
    remarkable_features = Column(JSON, comment='特别配置说明数组 (如: ["Double Air Bag", "After Market Alloy Wheels"])')
    
    # 统计信息
    image_count = Column(Integer, default=0, comment='关联图片数量')
    image_status = Column(String(20), default='pending', comment='图片下载状态: pending(待下载), downloading(下载中), completed(已完成), failed(失败)')
    
    # 商品状态标签  
    status_tag = Column(String(20), default='normal', comment='商品状态标签: normal(正常), sale(打折), new(新上), sold(售出)')
    
    def __repr__(self):
        return f"<VehiclePicknbuy24(ref_no='{self.ref_no}', year='{self.year}', make='{self.make}', model='{self.model}')>"